<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>纤程（Fiber）类</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="generator.wakeup.html">« Generator::__wakeup</a></li>
      <li style="float: right;"><a href="fiber.construct.html">Fiber::__construct »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="reserved.interfaces.html">预定义接口和类</a></li>
    <li>纤程（Fiber）类</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="class.fiber" class="reference">
 <h1 class="title">纤程（Fiber）类</h1>
 

 <div class="partintro"><p class="verinfo">(PHP 8 &gt;= 8.1.0)</p>


  <div class="section" id="fiber.intro">
   <h2 class="title">简介</h2>
   <p class="para">
    纤程（Fiber）代表了有完整栈、可中断的功能。Fiber 可以从调用堆栈中的任何位置挂起，在 fiber
    内暂停执行，直到稍后恢复 fiber。
   </p>
  </div>


  <div class="section" id="fiber.synopsis">
   <h2 class="title">类摘要</h2>


   <div class="classsynopsis">
    <div class="ooclass">
     
    </div>

    <div class="classsynopsisinfo">
     <span class="ooclass">
      <span class="modifier">final</span>
      <span class="modifier">class</span> <strong class="classname">Fiber</strong>
     </span>
     {</div>

    <div class="classsynopsisinfo classsynopsisinfo_comment">/* 方法 */</div>
    <div class="constructorsynopsis dc-description">
   <span class="modifier">public</span> <span class="methodname"><a href="fiber.construct.html" class="methodname">__construct</a></span>(<span class="methodparam"><span class="type"><a href="language.types.callable.html" class="type callable">callable</a></span> <code class="parameter">$callback</code></span>)</div>

    <div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="fiber.start.html" class="methodname">start</a></span>(<span class="methodparam"><span class="type"><a href="language.types.declarations.html#language.types.declarations.mixed" class="type mixed">mixed</a></span> <code class="parameter">...$args</code></span>): <span class="type"><a href="language.types.declarations.html#language.types.declarations.mixed" class="type mixed">mixed</a></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="fiber.resume.html" class="methodname">resume</a></span>(<span class="methodparam"><span class="type"><a href="language.types.declarations.html#language.types.declarations.mixed" class="type mixed">mixed</a></span> <code class="parameter">$value</code><span class="initializer"> = <strong><code>null</code></strong></span></span>): <span class="type"><a href="language.types.declarations.html#language.types.declarations.mixed" class="type mixed">mixed</a></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="fiber.throw.html" class="methodname">throw</a></span>(<span class="methodparam"><span class="type"><a href="class.throwable.html" class="type Throwable">Throwable</a></span> <code class="parameter">$exception</code></span>): <span class="type"><a href="language.types.declarations.html#language.types.declarations.mixed" class="type mixed">mixed</a></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="fiber.getreturn.html" class="methodname">getReturn</a></span>(): <span class="type"><a href="language.types.declarations.html#language.types.declarations.mixed" class="type mixed">mixed</a></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="fiber.isstarted.html" class="methodname">isStarted</a></span>(): <span class="type">bool</span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="fiber.issuspended.html" class="methodname">isSuspended</a></span>(): <span class="type">bool</span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="fiber.isrunning.html" class="methodname">isRunning</a></span>(): <span class="type">bool</span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="fiber.isterminated.html" class="methodname">isTerminated</a></span>(): <span class="type">bool</span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="modifier">static</span> <span class="methodname"><a href="fiber.suspend.html" class="methodname">suspend</a></span>(<span class="methodparam"><span class="type"><a href="language.types.declarations.html#language.types.declarations.mixed" class="type mixed">mixed</a></span> <code class="parameter">$value</code><span class="initializer"> = <strong><code>null</code></strong></span></span>): <span class="type"><a href="language.types.declarations.html#language.types.declarations.mixed" class="type mixed">mixed</a></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="modifier">static</span> <span class="methodname"><a href="fiber.getcurrent.html" class="methodname">getCurrent</a></span>(): <span class="type"><span class="type">?</span><span class="type"><a href="class.fiber.html" class="type Fiber">Fiber</a></span></span></div>

   }</div>


  </div>

  <div class="section" id="fiber.seealso">
   <h2 class="title">参见</h2>
   <p class="para"><a href="language.fibers.html" class="link">纤程概述</a></p>
  </div>

 </div>

 






 






 






 






 





 






 






 






 






 






 







<h2>目录</h2><ul class="chunklist chunklist_reference"><li><a href="fiber.construct.html">Fiber::__construct</a> — 创建新的 Fiber 实例</li><li><a href="fiber.start.html">Fiber::start</a> — 启动 fiber 的执行</li><li><a href="fiber.resume.html">Fiber::resume</a> — 使用值恢复 fiber 的执行</li><li><a href="fiber.throw.html">Fiber::throw</a> — 用一个异常来恢复 fiber 的执行</li><li><a href="fiber.getreturn.html">Fiber::getReturn</a> — 获取 Fiber 的返回值</li><li><a href="fiber.isstarted.html">Fiber::isStarted</a> — 确定 fiber 是否启动</li><li><a href="fiber.issuspended.html">Fiber::isSuspended</a> — 确认 fiber 是否挂起</li><li><a href="fiber.isrunning.html">Fiber::isRunning</a> — 确认 fiber 是否正在运行</li><li><a href="fiber.isterminated.html">Fiber::isTerminated</a> — 确认 fiber 是否终止</li><li><a href="fiber.suspend.html">Fiber::suspend</a> — 暂停当前 fiber 的执行</li><li><a href="fiber.getcurrent.html">Fiber::getCurrent</a> — 获取当前正在执行的 Fiber 实例</li></ul>
</div>
</div></div></body></html>